#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

const int N=305;
int n,m; 
int a[N];
int dp[N][N][N];

int main()
{
	freopen("build.in","r",stdin);
	freopen("build.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	rep(i,1,n) dp[i][i][a[i]]=1;
	rep(len,2,n) rep(i,1,n-len+1)
	{
		int j=i+len-1;
		rep(k,1,n-len+1)
		{
			chkmax(dp[i][j][k],dp[i+1][j][k+1]+(a[i]==k));
			chkmax(dp[i][j][k],dp[i+1][j][k]+(a[i]==k+len-1));
			chkmax(dp[i][j][k],dp[i][j-1][k+1]+(a[j]==k));
			chkmax(dp[i][j][k],dp[i][j-1][k]+(a[j]==k+len-1));
		}
	}
	rep(i,1,n) rep(k,1,n)
	{
		rep(j,1,min(n-i+1,n-k+1)) assert(dp[i][j][k]>=dp[i][j-1][k]);
	}
	cout << n-dp[1][n][1];
	return 0;
}
